import { BodySetup } from "utils/creep/CreepSetup";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";
import { EActionCode } from "framework/FSM/Action/ActionCode";
import { approach } from "GameLoop/WorldState/mount/move/action.virtual";

/**
 * 升级Action
 */
export class ActionUpgrade  extends ActionBaseOfCreep<IActionCMD<"upgrade">>
{
    protected _execute(action: IActionCMD<"upgrade">): ActionCode 
    {
        const controller = action.arg.controller;
        if(action.arg.entity.store.getUsedCapacity(RESOURCE_ENERGY) == 0)
        {
            return EActionCode.OK;
        }
        if(controller.pos.distance(action.arg.entity.pos)> action.arg.range)
        {
            action.arg.entity.mymoveTo({pos:controller.pos,range:1},{});
        }
        if(controller.pos.distance(action.arg.entity.pos)<=3 )
        {
            approach(action.arg.entity,controller.pos,3);
            action.arg.entity.upgradeController(action.arg.entity.room.controller!);
        }
        
         return EActionCode.RUNNING;
    }
}